package cn.yj.core.newStudent;

import cn.yj.cgs.dba.entity.Gift;
import cn.yj.config.web.AppBaseController;
import cn.yj.entity.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 永健
 * @since 2021-07-24 15:29
 */
@RestController
@RequestMapping("/newStudent")
public class NewStudentController extends AppBaseController {

    @Resource
    private IGiftService giftService;

    @PostMapping("/save")
    public R save(@RequestBody Gift gift) {
        return result(giftService.save(gift.getLetterPath(),getUserCode()));
    }

    @GetMapping("/getLetterPath")
    public R getLetterPath() {
        return success(giftService.getOne(new QueryWrapper<Gift>().lambda().eq(Gift::getUserCode, getUserCode())));
    }

    @DeleteMapping("/delete")
    public R delete() {
        return result(giftService.remove(new UpdateWrapper<Gift>().lambda().eq(Gift::getUserCode, getUserCode())));
    }

    @GetMapping("/count")
    public R count() {
        return success(giftService.countAll(getUserCode()));
    }
}
